package com.yungu.swift.api.route.v2.passenger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.assets.driver.model.vo.ScanCodeDriverInfoVo;
import com.yungu.swift.assets.driver.service.CarService;
import com.yungu.swift.assets.driver.service.DriverService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.annotation.ResponseImgOverride;
import com.yungu.swift.order.service.OrderService;
import com.yungu.swift.system.sys.model.dto.SysWayDto;
import com.yungu.swift.system.sys.service.SysWayService;
import com.yungu.swift.utils.StringUtils;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/api/v2/passenger")
@Api(value = "【乘客】【订单】乘客跨城订单操作相关接口", tags = "乘客跨城订单相关")
public class CrosstownOrderApi {

    @Reference
    private OrderService orderService;
    @Reference
    private SysWayService sysWayService;
    @Reference
    private DriverService driverService;
    @Reference
    private CarService carService;

    /**
     * 获取出发时间配置
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/token/getDeparTimeConfig")
    public ResponseData<Map<String, Object>> getDepartTimeConfig(@RequestBody Map<String, Object> paraMap) {
        if (paraMap.get("originSiteUuid") == null || paraMap.get("destSiteUuid") == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "起点终点ID不能为空");
        }
        SysWayDto sysWayDto = sysWayService.get(paraMap).getData();
        if (sysWayDto == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "线路不存在");
        }
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("integralTimeDepart", sysWayDto.getIntegralTimeDepart());
        resultMap.put("halfTimeDepart", sysWayDto.getHalfTimeDepart());
        resultMap.put("startTime", sysWayDto.getStartTime());
        resultMap.put("endTime", sysWayDto.getEndTime());
        return ResponseData.buildSuccessResponse(resultMap);
    }

    /**
     * 下单获取司机信息
     */
    @ResponseImgOverride
    @ResponseBody
    @RequestMapping("/scanCodeGetDriverInfo")
    public ResponseData<ScanCodeDriverInfoVo> scanCodeGetDriverInfo(@RequestBody Map<String, String> map) {
        String driverUuid = map.get("driverUuid");
        if (StringUtils.isEmpty(driverUuid)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "司机ID不能为空");
        }
        ScanCodeDriverInfoVo scanCodeDriverInfoVo = driverService.getScanCodeDriverInfo(driverUuid).getData();
        if (scanCodeDriverInfoVo == null) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "获取失败");
        }
        return ResponseData.buildSuccessResponse(scanCodeDriverInfoVo);
    }
}
